package com.ceuer.initvaule;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;
import java.util.Map;

@Configuration
public class Config implements WebMvcConfigurer {
	@Value("${filepath}")
	private String filepath;
	
	//常规引用
	@Value("${map.uploadfiledir}")
	private String uploadfile1;
	
	//SpEL表达式
	@Value("#{'${map.uploadfiledir}'}")
	private String uploadfile2;
	
	@Value("${map.uploadfiledir:#{null}}")
	private String uploadfile3;
	
	@Value("${map.uploadfiledir1:123}")
	private String uploadfile4;
	
	@Value("${map.uploadfiledir1:#{null}}")
	private String uploadfile5;
	
	@Value("#{${map1}}")
	private Map<String, String> map1;
	
	@Value("#{${map2}}")
	private Map<String, List<String>> map2;
	
	@Value("#{${map3}}")
	private Map<String, Map<String, String>> map3;
	
	@Value("#{${map3}?:null}")
	private Map<String, Map<String, String>> map4;
	
	@Value("#{${map3:{:}}}")
	private Map<String, Map<String, String>> map5;
	
	@Value("#{${resmap:{:}}}")
	private Map<String, Map<String, String>> resmap;
	
	@Value("${cache.enabled:false}")
	private boolean cacheEnabled;
	
	@Value("#{'${interceptor.token.excludePaths}'.split(',')}")
	private List<String> tokenExcludePaths;
	
	//添加默认值默认使用:
	@Value("#{'${interceptor.token.excludePaths1:}'.split(',')}")
	private List<String> tokenExcludePaths1;
	
	//添加默认值默认使用:
	@Value("#{'${interceptor.token.excludePaths2:}'.empty ? null : '${interceptor.token.excludePaths2:}'.split(',')}")
	private List<String> tokenExcludePaths2;
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		System.out.println("filepath--->"+filepath);
		
		System.out.println("uploadfile1--->"+uploadfile1);
		System.out.println("uploadfile2--->"+uploadfile2);
		System.out.println("uploadfile3--->"+uploadfile3);
		System.out.println("uploadfile4--->"+uploadfile4);
		System.out.println("uploadfile5--->"+uploadfile5);
		
		System.out.println(map1);
		System.out.println(map2);
		System.out.println(map3);
		System.out.println(map4);
		System.out.println(map5);
		System.out.println(resmap);
		
		System.out.println(cacheEnabled);
		
		System.out.println(tokenExcludePaths);
		System.out.println(tokenExcludePaths1);
		System.out.println(tokenExcludePaths2);
		
	}
	
	// @Bean
	// public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
	// 	PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
	// 	c.setIgnoreUnresolvablePlaceholders(true);
	// 	return c;
	// }
	
}
